var http = require('../../../../utils/http')
Page({

    data: {
        userinfo: {},
        username: '',
        switch1: false,
        switch2: false,
        relation: {
            userAId: 0,
            userBId: 0
        },
        avatar:'',
        nickName:''
    },

    onLoad(options) {
        const userInfo = wx.getStorageSync('userInfo')
        this.setData({
            'relation.userAId': userInfo.id,
        })
    },

    search_user() {
        const that = this;
        if (this.data.username) {
            http.post("/mini/findByUsername",that.data.username,res=>{
                if (res.data.data) {
                    that.setData({
                        switch1: true,
                        switch2: false,
                        'relation.userBId': res.data.data.id,
                        avatar: res.data.data.avatar,
                        nickName: res.data.data.nickName
                    })
                } else {
                    that.setData({
                        switch1: false,
                        switch2: true
                    })
                }
            })
        } else {
            this.data.nickName = '',
            this.data.avatar = ''
        }
    },
    addfriend(e) {
         http.post("/mini/addFriend",this.data.relation,res=>{
            wx.showToast({
                title: '申请好友成功',
            })
         })
    }

})